<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        <button onclick="sum()">N个随机整数/和</button>
        function sum(){
        var n=parseInt(prompt("输入n:"));
        if(!isNaN(n)){
        var sum=0;
        for( var i=0;i<n;i++){
        var num=Math.floor(Math.random()*9000)+1000;
        sum+=num;
        document.write(num+',');
        }
        document.write(n+"个随机4位数是：“+<br>" +n+"随机4位整数的和是：");
    }
}
    </script>
</body>
</html>